import axios from "axios";
axios.defaults.baseURL = "/api";
axios.interceptors.request.use(
  function (config) {
    // 发送请求前如果有token，请求头携带token
    let token = sessionStorage.getItem("token");
    // token && (config.headers.token = token);
    return config;
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// Add a response interceptor
axios.interceptors.response.use(
  function (response) {
    return response;
  },
  function (error) {
    console.log("err", error);
    // switch (error.response.status) {
    //   case 401:
    //     alert("token过期");
    //     window.location.href = "/";
    //     break;
    // }
    return Promise.reject(error);
  }
);
export default axios;
